<template>
  <nav class="navbar is-light" role="navigation" aria-label="main navigation">
    <div class="navbar-brand">
      <a class="navbar-item" href="https://bulma.io">
        <img src="https://bulma.io/images/bulma-logo.png" width="112" height="28" />
      </a>

      <a
        role="button"
        class="navbar-burger burger"
        aria-label="menu"
        aria-expanded="false"
        data-target="navbarBasicExample"
      >
        <span aria-hidden="true"></span>
        <span aria-hidden="true"></span>
        <span aria-hidden="true"></span>
      </a>
    </div>

    <div id="navbarBasicExample" class="navbar-menu">
      <div class="navbar-start">
        <a class="navbar-item" @click = "to_forumHome">首页</a>

        <a class="navbar-item" @click= "changeList">精华</a>
        <div class="navbar-item has-dropdown is-hoverable">
          <a class="navbar-link">更多</a>

          <div class="navbar-dropdown">
            <a class="navbar-item" @click="userhome">个人主页</a>
            <a v-if="is_manager == 1" class="navbar-item" @click="checkCenter">管理员中心</a>
            <a  class="navbar-item" @click="to_login">登出</a>
            <hr class="navbar-divider" />
            <a class="navbar-item">Report an issue</a>
          </div>
        </div>
        <div class="level-left">
          <div class="level-item">
            <p class="subtitle is-5"></p>
          </div>
          <div class="level-item">
            <div class="field has-addons">
              <p class="control">
                <input class="input" type="text"  v-model ="searchMessage" placeholder="Find a post" />
              </p>
              <p class="control">
                <button class="button" @click="search">搜索</button>
              </p>
            </div>
          </div>
        </div>
      </div>

      <div class="navbar-end" v-if="!$store.state.isLogin">
        <div class="navbar-item">

        </div>
      </div>

    </div>
  </nav>
</template>

<script>
// import { userLogin } from "@/api";

export default {
  data() {
    return {
      email: "",
      password: "",
      searchMessage:'',
    };
  },
  props: {
    is_manager:{
      type:Number,
      require:true
    }
  },
  inject:['reload'],
  methods: {
    to_forumHome(){
       this.$router.push("/forumHome");
        this.reload()
    },
    userhome() {
      this.$router.push("/userHome");
       this.reload()
    },
    checkCenter() {
      this.$router.push("/check");
       this.reload()
    },
    // login() {
    //   userLogin(this.email, this.password) 
    //     .then(res => {
    //       const { data } = res;
    //       this.user = data;
    //       console.log(data);
    //       if (data != null) {
    //         this.$store.dispatch("aLogin", {
    //           user: data,
    //           message: "牛逼",
    //           success: () => {
    //             console.log("欢迎您");
    //           }
    //         });
    //       } else {
    //         alert("该用户不存在");
    //       }
    //     })
    //     .catch(() => {});
    // },
    // register() {
    //   this.$router.push("/registerhome");
    // },
    to_login(){
      this.$router.push('/')
    },
    changeList(){
      this.$router.push({
          path: `/theme_list/${1}`,
        })
      this.reload()
    },
    search(){
      let message = this.searchMessage
      if(message == null || message == ''){
         alert("请输入恰当的内容！！");
         this.searchMessage = ''
      }else{
        this.message = ''
         this.$router.push({
          path: `/search/${message}`,
        })
          this.reload()
      }
    }
  }
};
</script>
